/*
 * Copyright (c) 2024 Black Sesame Technologies
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "dal_rticonnextdds/converter/RetTypeConverter.hpp"

RetTypeConverter* RetTypeConverter::singleton_ = nullptr;

RetTypeConverter::RetTypeConverter() {}

RetTypeConverter* RetTypeConverter::GetInstance()
{
    if (singleton_ == nullptr) {
        singleton_ = new RetTypeConverter();
    }
    return singleton_;
}

dal_ret_t RetTypeConverter::ConvertRetFromRtiddsToDal(DDS_ReturnCode_t r_ret)
{
    if (DDS_RETCODE_OK == r_ret)
        return DAL_RETCODE_OK;
    if (DDS_RETCODE_ERROR == r_ret)
        return DAL_RETCODE_ERROR;
    if (DDS_RETCODE_UNSUPPORTED == r_ret)
        return DAL_RETCODE_UNSUPPORTED;
    if (DDS_RETCODE_BAD_PARAMETER == r_ret)
        return DAL_RETCODE_BAD_PARAMETER;
    if (DDS_RETCODE_PRECONDITION_NOT_MET == r_ret)
        return DAL_RETCODE_PRECONDITION_NOT_MET;
    if (DDS_RETCODE_OUT_OF_RESOURCES == r_ret)
        return DAL_RETCODE_OUT_OF_RESOURCES;
    if (DDS_RETCODE_NOT_ENABLED == r_ret)
        return DAL_RETCODE_NOT_ENABLED;
    if (DDS_RETCODE_IMMUTABLE_POLICY == r_ret)
        return DAL_RETCODE_IMMUTABLE_POLICY;
    if (DDS_RETCODE_INCONSISTENT_POLICY == r_ret)
        return DAL_RETCODE_INCONSISTENT_POLICY;
    if (DDS_RETCODE_ALREADY_DELETED == r_ret)
        return DAL_RETCODE_ALREADY_DELETED;
    if (DDS_RETCODE_TIMEOUT == r_ret)
        return DAL_RETCODE_TIMEOUT;
    if (DDS_RETCODE_NO_DATA == r_ret)
        return DAL_RETCODE_NO_DATA;
    if (DDS_RETCODE_ILLEGAL_OPERATION == r_ret)
        return DAL_RETCODE_ILLEGAL_OPERATION;
    return DAL_RETCODE_RESERVED;
}